import { app, appEvent, Config, startApp } from './app';
import { Server } from 'http';
import { makeLabelLogger, llog } from './util/logger';
import { bindSocketIO } from './socket';
import { orderModel } from './models/Order';

export let server: Server;

startApp();
appEvent.addListener('inited', async () => {
	server = app.listen(Config.getPort(), '0.0.0.0');
	server.on('error', e => {
		if (/listen EADDRINUSE/.test(e.message)) {
			console.log('ignore temp addr error');
		} else {
			console.log('server error', e.message);
		}
	});
	bindSocketIO(server);
	llog('** api server is listening on port : ' + Config.getPort());
});
